package com.test.springai.config;

import com.alibaba.cloud.ai.memory.jdbc.SQLiteChatMemoryRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 9/5/25 3:55 PM
 * @modifiedBy:
 * @version: 1.0
 */
@Configuration
public class SqliteMemoryConfig {

  @Bean
  public SQLiteChatMemoryRepository sqliteChatMemoryRepository() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("org.sqlite.JDBC");
    dataSource.setUrl("jdbc:sqlite:spring-ai-test/db/chat-memory.db");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    return SQLiteChatMemoryRepository.sqliteBuilder().jdbcTemplate(jdbcTemplate).build();
  }
}
